﻿using System;
using System.Runtime.Serialization;
using LiSA_Server.Base.NHibernate.Models;
using LiSA_Service.Enums;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Type;

namespace LiSA_Service.Users.Models
{
    [DataContract]
    /// <summary>
    /// Describes the role for a given project. 
    /// Used to determine access capabilities for a user.
    /// </summary>
    public class Permission : Entity
    {
        /// <summary>
        /// ID of a project
        /// </summary>
        [DataMember]
        public virtual Guid ProjectID { get; set; }


        /// <summary>
        /// ID of the user with the permission
        /// </summary>
        [DataMember]
        public virtual Guid UserID { get; set; }

        /// <summary>
        /// Users access role for the given project
        /// </summary>
        [DataMember]
        public virtual Role Role { get; set; }
    }

    /// <summary>
    /// The person mapping.
    /// </summary>
    public class PermissionMapping : ClassMapping<Permission>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PermissionMapping"/> class.
        /// </summary>
        public PermissionMapping()
        {
            this.Property(x => x.ProjectID);
            this.Property(x => x.UserID);
            this.Property(x => x.Role, m => m.Type<EnumStringType<Role>>());
        }
    }
}